< Prev(J) / Next(K) > / View :

Filename: /text/sbasic/shared/03132000.xhp

(section: createunolistener) (bookmark: bm_id3155150)
CreateUnoListener function

CreateUnoListener 関数

CreateUnoListener Function [Runtime]
CreateUnoListener 関数 [実行時](hd_id3155150.53)

Creates a Listener instance.
リスナーインスタンスを作成します。(par_id3149346.52)

(/section: createunolistener)

Many Uno interfaces let you register listeners on a special listener interface. This allows you to listen for specific events and call up the appropriate listener method. The CreateUnoListener function waits for the called listener interface and then passes the interface an object that the interface supports. This object is then passed to the method to register the listener.
Uno インタフェースの多くでは、リスナーを特殊なリスナーインタフェースに登録することができます。これにより、特定のイベントの発生を監視して、必要なリスナーメソッドを呼び出すことができます。CreateUnoListener 関数は、呼び出されたリスナーインタフェースの到着を待ち、そのインタフェースのサポートするオブジェクトへ、インタフェースを引き渡します。次にこのオブジェクトはメソッドへ引き渡されてリスナーが登録されます。(par_id3153681.51)

Syntax:
構文:(hd_id3148685.50)

oListener = CreateUnoListener( Prefixname, ListenerInterfaceName )
oListener = CreateUnoListener( Prefixname, ListenerInterfaceName )(par_id3143228.49)

Example:
例:(hd_id3147574.48)

The following example is based on a Basic library object.
下記の例は、Basic ライブラリオブジェクトをベースにしています。(par_id3154046.47)

Dim oListener
Dim oListener(par_id3155136.46)

oListener = CreateUnoListener( "ContListener_","com.sun.star.container.XContainerListener" )
oListener = CreateUnoListener( "ContListener_","com.sun.star.container.XContainerListener" )(par_id3148944.45)

The CreateUnoListener method requires two parameters. The first is a prefix and is explained in detail below. The second parameter is the fully qualified name of the Listener interface that you want to use.
CreateUnoListener メソッドは、2 つのパラメータを使用します。1 番目のパラメータはプレフィックスで、詳細は後述します。2 番目のパラメータは、使用する Listener インタフェースの完全な名前です。(par_id3149294.44)

The Listener must then be added to the Broadcaster Object. This is done by calling the appropriate method for adding a Listener. These methods always follow the pattern "addFooListener", where "Foo" is the Listener Interface Type, without the 'X'. In this example, the addContainerListener method is called to register the XContainerListener:
Listener は Broadcaster Object に追加する必要があります。この処理は、Listener 追加用のメソッドを呼び出すことで実行します。通常こうしたメソッドの取るパターンは「addFooListener」という形式で、ここで「Foo」が Listener Interface Type で「X」は付きません。ここでの例では、addContainerListener メソッドを呼び出して XContainerListener を登録しています。(par_id3149670.43)

Dim oLib
Dim oLib(par_id3154164.42)

oLib = BasicLibraries.Library1 ' Library1 must exist!
oLib = BasicLibraries.Library1 ' Library1 の存在が必要(par_id3154940.41)

oLib.addContainerListener( oListener ) ' Register the listener
oLib.addContainerListener( oListener ) ' リスナーの登録(par_id3150359.40)

The Listener is now registered. When an event occurs, the corresponding Listener calls the appropriate method from the com.sun.star.container.XContainerListener Interface.
これで Listener が登録されます。イベントが発生すると、該当する Listener が com.sun.star.container.XContainerListener Interface から呼び出されます。(par_id3154138.39)

The prefix calls registered Listeners from Basic-subroutines. The Basic run-time system searches for Basic-subroutines or functions that have the name "PrefixListenerMethode" and calls them when found. Otherwise, a run-time error occurs.
プレフィックスは、登録した Listener を Basic サブルーチンから呼び出します。Basic の実行時システムは、「PrefixListenerMethod」という名前の Basic サブルーチンや関数を検索して、該当するものを発見した段階でこれらを呼び出します。該当するものが存在しないと、実行時エラーが発生します。(par_id3148922.38)

In this example, the Listener-Interface uses the following methods:
ここでの例では、Listener-Interface は下記のメソッドを利用しています。(par_id3150768.37)

In this example, the prefix is ContListener_. The following subroutines must therefore be implemented in Basic:
ここでの例では、プレフィックスを ContListener_ としています。このため下記のサブルーチン群を Basic に実装しておく必要があります。(par_id3147435.28)

An event structure type that contains information about an event exists for every Listener type. When a Listener method is called, an instance of this event is passed to the method as a parameter. Basic Listener methods can also call these event objects, so long as the appropriate parameter is passed in the Sub declaration. For example:
Listener の種類ごとに、イベント情報を格納するイベント構造型が存在します。Listener メソッドが呼び出されると、このイベントのインスタンスがメソッドにパラメータとして渡されます。Basic の Listener メソッドは、該当するパラメータが Sub 宣言部で渡される限り、これらのイベントオブジェクトを呼び出すこともできます。たとえば、(par_id3150592.23)

Sub ContListener_disposing( oEvent )
Sub ContListener_disposing( oEvent )(par_id3149582.22)

MsgBox "disposing"
MsgBox "disposing"(par_id3153876.21)

MsgBox oEvent.Dbg_Properties
MsgBox oEvent.Dbg_Properties(par_id3149959.20)

End Sub
End Sub(par_id3154490.19)

Sub ContListener_elementInserted( oEvent )
Sub ContListener_elementInserted( oEvent )(par_id3156285.18)

MsgBox "elementInserted"
MsgBox "elementInserted"(par_id3154098.17)

MsgBox oEvent.Dbg_Properties
MsgBox oEvent.Dbg_Properties(par_id3155601.16)

End Sub
End Sub(par_id3153415.15)

Sub ContListener_elementRemoved( oEvent )
Sub ContListener_elementRemoved( oEvent )(par_id3154272.14)

MsgBox "elementRemoved"
MsgBox "elementRemoved"(par_id3153947.13)

MsgBox oEvent.Dbg_Properties
MsgBox oEvent.Dbg_Properties(par_id3146914.12)

End Sub
End Sub(par_id3150749.11)

Sub ContListener_elementReplaced( oEvent )
Sub ContListener_elementReplaced( oEvent )(par_id3145642.10)

MsgBox "elementReplaced"
MsgBox "elementReplaced"(par_id3148915.9)

MsgBox oEvent.Dbg_Properties
MsgBox oEvent.Dbg_Properties(par_id3148995.8)

End Sub
End Sub(par_id3148407.7)

You do not need to include the parameter of an event object if the object is not used:
使用しないオブジェクトについては、イベントオブジェクトのパラメータを省略できます。(par_id3156056.6)

' Minimal implementation of Sub disposing
' disposing 用 Sub の最小構成(par_id3150042.5)

Sub ContListener_disposing
Sub ContListener_disposing(par_id3151249.4)

End Sub
End Sub(par_id3155333.3)

Warning Icon 警告マーク Listener methods must always be implemented to avoid Basic run-time errors.
Basic の実行時エラーを回避するため、Listener メソッドは 常に 実装しておく必要があります。(par_id3150940.2)


< Prev / Next >